Skip to content

fix: use core instead of std - #741

Draft
xtqqczze wants to merge 2 commits into
rust-lang:mainfrom
xtqqczze:clippy/std_instead_of_core
Draft

fix: use core instead of std#741
xtqqczze wants to merge 2 commits into
rust-lang:mainfrom
xtqqczze:clippy/std_instead_of_core

Conversation

@xtqqczze

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread benches/general_ops.rs Outdated
Comment thread src/map.rs
///
/// // Existing key (or_insert)
/// let v = map.entry("b").or_insert(2);
/// assert_eq!(std::mem::replace(v, 2), 20);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly in favour of this change, but I would rather not update the doctests specifically since in general we prefer making those as simple as possible, and using only std allows better import grouping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import grouping shouldn’t be an issue here. In the doctests, we only use the following std imports, and they are never used in combination with core:

/// use std::hash::RandomState;
/// use std::rc::Rc;

Comment thread src/raw.rs Outdated
Comment thread tests/hasher_unwind.rs
Comment on lines +18 to +20
use std::collections::BTreeSet;
use std::panic::catch_unwind;
use std::sync::Mutex;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would brace-group these:

Suggested change
use std::collections::BTreeSet;
use std::panic::catch_unwind;
use std::sync::Mutex;
use std::{
collections::BTreeSet,
panic::catch_unwind,
sync::Mutex,
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered that, but rustfmt wanted to remove whitespace which I didn't like:

use std::{collections::BTreeSet, panic::catch_unwind, sync::Mutex};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see; personally, I still would go with it, but it's up to you.

@xtqqczze xtqqczze Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world, we'd use imports_layout = "Vertical" like libc but it's an unstable feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clarfonthey By the way, would you prefer a fixup commit or rebase?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the main repo we don't want nested merge commits so a rebase would be ideal. Don't really mind if the result is multiple commits, although figured you'd also squash them as well anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to propose new rustfmt.toml changes, wouldn't actually mind that, since formatting in CI is always via nightly. But probably better as a separate PR which can be ignored on blame.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, yeah. Since the repo doesn’t use squash merges, I think a rebase is needed despite any reviewer preference.

@xtqqczze
xtqqczze marked this pull request as draft July 28, 2026 14:29
xtqqczze added 2 commits July 29, 2026 17:10
`std::collections::hash_map::RandomState` moved to `std::RandomState` in Rust 1.76.
@xtqqczze
xtqqczze force-pushed the clippy/std_instead_of_core branch from 89b0299 to 0119920 Compare July 29, 2026 16:11
@clarfonthey

Copy link
Copy Markdown
Contributor

FWIW: there are clippy lints for alloc_instead_of_core, std_instead_of_core, and std_instead_of_alloc. Don't think they can be set up to exclude doctests though.

@clarfonthey

Copy link
Copy Markdown
Contributor

At the moment, LGTM minus the clippy lints to help avoid this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants